/*
 * @Author: 13177709051 3506463075@qq.com
 * @Date: 2024-11-06 17:37:30
 * @LastEditors: 13177709051 3506463075@qq.com
 * @LastEditTime: 2024-11-08 14:25:28
 * @FilePath: /test/json2.cpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include <iostream>
#include <sstream>
#include <string>
#include <memory>
#include <jsoncpp/json/json.h>

int main()
{
    std::string str = R"({"姓名":"小明", "年龄":18, "成绩":[76.5, 55, 88]})";
    Json::Value root;
    Json::CharReaderBuilder crb;
    std::unique_ptr<Json::CharReader> cr(crb.newCharReader());

    std::string err;
    cr->parse(str.c_str(), str.c_str() + str.size(), &root, &err);

    std::cout << root["姓名"].asString() << std::endl;
    std::cout << root["年龄"].asInt() << std::endl;
    int sz = root["成绩"].size();
    for(int i = 0; i < sz; i++)
    {
        std::cout << root["成绩"][i].asFloat() << std::endl;
    }
    for(auto it = root["成绩"].begin(); it != root["成绩"].end(); it++)
    {
        std::cout << it->asFloat() << std::endl;
    }
    return 0;
}